package com.sport.controller;

import com.alibaba.fastjson.JSON;
import com.sport.dao.MenuDao;
import com.sport.dto.MainMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
public class MenuController {
    @Autowired
    MenuDao menuDao;

    @CrossOrigin
    @RequestMapping("/menus")
    public String getAllMenus(){
        System.out.println("成功访问！！！");
        HashMap<String, Object> data = new HashMap<>();
        List<MainMenu> mainMenus = menuDao.getMenus();
        if (mainMenus!=null){
            data.put("menus",mainMenus);
            data.put("flag",200);
        }
        String s = JSON.toJSONString(data);
        return s;
    }
}
